package com.example.quanlithuchi;

import Enum.ThongKeThuchiEnum;
import ViewClass.ConcreateFactoryQuy;
import ViewClass.ConcreateFactoryThang;
import ViewClass.ConcreateFactory_thoigian;
import ViewClass.IViewFactory;
import android.os.Bundle;
import android.app.Activity;
import android.app.Dialog;
import android.content.Context;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.CompoundButton.OnCheckedChangeListener;
import android.widget.CompoundButton;
import android.widget.EditText;
import android.widget.RadioButton;
import android.widget.RelativeLayout;
import android.widget.Toast;

public class ThongkeActivity extends Activity {

	RelativeLayout menu_layout;
	RadioButton rdo_quy,rdo_thang,rdo_thoigian;
	Button btnthongke;
	ThongKeThuchiEnum thongKeThuchiEnum=ThongKeThuchiEnum.none;
	EditText txtQuy;
	EditText txtthangEditText,txtfromdate,txttodate,txtnam;
	Context context=this;
	int nam;
	int thang;
	int quy;
	long fromdate,todate;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_thongke);
		setTitle("thống kê");
		menu_layout=(RelativeLayout) findViewById(R.id.layout_menu);
		rdo_quy=(RadioButton) findViewById(R.id.rdo_quy);
		rdo_quy.setOnClickListener(onthongke);
		rdo_thang=(RadioButton) findViewById(R.id.rdo_thang);
		rdo_thang.setOnClickListener(onthongke);
		rdo_thoigian=(RadioButton) findViewById(R.id.rdo_thoigian);
		rdo_thoigian.setOnClickListener(onthongke);
		btnthongke=(Button) findViewById(R.id.btnthongke);
		btnthongke.setOnClickListener(onthongke);
		IViewFactory viewFactory=new ConcreateFactoryQuy();
		View myview=viewFactory.getIViewClass().getView(getLayoutInflater());
		menu_layout.addView(myview);
		thongKeThuchiEnum=ThongKeThuchiEnum.quy;
		txtnam=(EditText) findViewById(R.id.txtnamthongke);
		txtQuy=(EditText) myview.findViewById(R.id.txtquy);
		
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.activity_thongke, menu);
		return true;
	}
	OnClickListener onthongke=new OnClickListener() {
		
		@Override
		public void onClick(View view) {
			// TODO Auto-generated method stub
			switch (view.getId()) {
			case R.id.rdo_quy:
			{
				menu_layout.removeAllViews();
				IViewFactory viewFactory=new ConcreateFactoryQuy();
				View myview=viewFactory.getIViewClass().getView(getLayoutInflater());
				txtQuy=(EditText) myview.findViewById(R.id.txtquy);
				menu_layout.addView(myview);
				thongKeThuchiEnum=ThongKeThuchiEnum.quy;
			}
				
				break;
			case R.id.rdo_thang:
			{
				menu_layout.removeAllViews();
				IViewFactory viewFactory=new ConcreateFactoryThang();
				View myview=viewFactory.getIViewClass().getView(getLayoutInflater());
				txtthangEditText=(EditText) myview.findViewById(R.id.txtthang);
				menu_layout.addView(myview);
				thongKeThuchiEnum=ThongKeThuchiEnum.thang;
			}
				
				break;
			case R.id.rdo_thoigian:
			{
				menu_layout.removeAllViews();
				IViewFactory viewFactory=new ConcreateFactory_thoigian();
				View myview=viewFactory.getIViewClass().getView(getLayoutInflater());
				txtfromdate=(EditText) myview.findViewById(R.id.txtfromdate);
				txttodate=(EditText) myview.findViewById(R.id.txttodate);
				menu_layout.addView(myview);
				thongKeThuchiEnum=ThongKeThuchiEnum.thoigian;
			}
			case R.id.btnthongke:
			{
				try {
					 nam=Integer.parseInt(txtnam.getText().toString());
					if (nam<0) {
						show("nam thong ke phai lon hon khong");return;
					}
				} catch (Exception e) {
					// TODO: handle exception
					show("ban phai nhap nam thong ke");
					return;
				}
				switch (thongKeThuchiEnum) {
				case quy:
				{
					try {
						 quy=Integer.parseInt(txtQuy.getText().toString());
						if (quy<1||quy>4) {
							
							show("ban phai nhap gia tri tu 1 den 4");
							return;
						}else {
							
						}
					} catch (Exception e) {
						// TODO: handle exception
						show("ban phai nhap quy thong ke");
						return;
					}
					
					
				}
					break;
				case thang:
				{
					try {
						 thang=Integer.parseInt(txtthangEditText.getText().toString());
						if (thang<1||thang>12) {
							
							show("ban phai nhap gia tri cua thang nam trong khoang tu 1 den 12");
							return;
						}else {
							
						}
					} catch (Exception e) {
						// TODO: handle exception
						show("ban phai nhap thang thong ke");
						return;
					}
				}
					break;
				case thoigian:
				{
					
				}
					break;

				
				}
			}
				
				break;

			
			}
		}
	};
	@Override
	protected Dialog onCreateDialog(int id) {
		// TODO Auto-generated method stub
		return super.onCreateDialog(id);
	}
	void show(String text)
	{
		Toast.makeText(context, text,Toast.LENGTH_LONG).show();
	}
	
	

}
